﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using NUnit.Framework;
using DBSourceToolsLib;


namespace TestDBSourceToolsLibNUnit
{
    [TestFixture]
    [Ignore]
    public class TestDirectoryList
    {
        private const string strControlPath = BaseDirectoryHelper.Unused + "\\control";
        private const string strOutputPath = BaseDirectoryHelper.Unused + "\\output";

        [Test]
        public void TestDCFile() 
        {
            DBSourceToolsLib.FileComparer.DirectoryList oDC = new DBSourceToolsLib.FileComparer.DirectoryList(strControlPath, strOutputPath);
            DBSourceToolsLib.FileComparer.DCFile oDCFile = new DBSourceToolsLib.FileComparer.DCFile(
                "c:\\temp\\tempdir\\test.txt", "c:\\temp", oDC);
            Assert.IsTrue(oDCFile.GetRelativeFileName().CompareTo("\\tempdir\\test.txt") == 0,
                " DCFile RelativeFileName should be \\tempdir\\test.txt : " + oDCFile.GetRelativeFileName());
        }

        [Test]
        public void TestDCDirectoryList()
        {
            string strExpectedOutput = GetExpectedOutput();


            DBSourceToolsLib.FileComparer.DirectoryList oDirComp =
                new DBSourceToolsLib.FileComparer.DirectoryList(strControlPath + "\\testDirCompSource", strControlPath + "\\testDirCompTarget");

            Assert.IsTrue(oDirComp.SourceFiles.Count == 12, " SourceFile count should be 12");
            Assert.IsTrue(oDirComp.TargetFiles.Count == 12, " TargetFile count should be 12");

            Assert.IsTrue(oDirComp.GetSourceString().CompareTo(strExpectedOutput) == 0, "SourceString invalid");
            Assert.IsTrue(oDirComp.GetTargetString().CompareTo(strExpectedOutput) == 0, "TargetString invalid");
            
        }

        private string GetExpectedOutput()
        {
            StringBuilder oBuilder = new StringBuilder();
            oBuilder.AppendLine("\\PatternsDB");
            oBuilder.AppendLine("\\PatternsDB\\Run_Create_Scripts.bat");
            oBuilder.AppendLine("\\PatternsDB\\Functions");
            oBuilder.AppendLine("\\PatternsDB\\Functions\\fn_Test.sql");
            oBuilder.AppendLine("\\PatternsDB\\Procs");
            oBuilder.AppendLine("\\PatternsDB\\Procs\\long_proc.sql");
            oBuilder.AppendLine("\\PatternsDB\\Procs\\prc_TestProc.sql");
            oBuilder.AppendLine("\\PatternsDB\\Tables");
            oBuilder.AppendLine("\\PatternsDB\\Tables\\TestTable.sql");
            oBuilder.AppendLine("\\PatternsDB\\Tables\\TestTable_1.sql");
            oBuilder.AppendLine("\\PatternsDB\\Views");
            oBuilder.AppendLine("\\PatternsDB\\Views\\TestView_1.sql");
            return oBuilder.ToString();
        }
        
    }
}
